<!DOCTYPE html>
<html lang="en-us">
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    
<meta charset="UTF-8">
<title>Install Elasticsearch with Docker | Elasticsearch Guide [7.7] | Elastic</title>
<link rel="home" href="index.html" title="Elasticsearch Guide [7.7]">
<link rel="up" href="install-elasticsearch.html" title="Installing Elasticsearch">
<link rel="prev" href="windows.html" title="Install Elasticsearch with Windows MSI Installer">
<link rel="next" href="brew.html" title="Install Elasticsearch on macOS with Homebrew">
<meta name="DC.type" content="Learn/Docs/Elasticsearch/Reference/7.7">
<meta name="DC.subject" content="Elasticsearch">
<meta name="DC.identifier" content="7.7">
<meta name="robots" content="noindex,nofollow">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://cdn.optimizely.com/js/18132920325.js"></script>
    <link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
    <link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
    <link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
    <link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
    <link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
    <link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
    <link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
    <link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">
    <link rel="icon" type="image/png" href="/android-chrome-192x192.png" sizes="192x192">
    <link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">
    <link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
    <link rel="manifest" href="/manifest.json">
    <meta name="apple-mobile-web-app-title" content="Elastic">
    <meta name="application-name" content="Elastic">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="msapplication-TileImage" content="/mstile-144x144.png">
    <meta name="theme-color" content="#ffffff">
    <meta name="naver-site-verification" content="936882c1853b701b3cef3721758d80535413dbfd">
    <meta name="yandex-verification" content="d8a47e95d0972434">
    <meta name="localized" content="true">
    <meta name="st:robots" content="follow,index">
    <meta property="og:image" content="https://www.elastic.co/static/images/elastic-logo-200.png">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" href="/favicon.ico" type="image/x-icon">
    <link rel="apple-touch-icon-precomposed" sizes="64x64" href="/favicon_64x64_16bit.png">
    <link rel="apple-touch-icon-precomposed" sizes="32x32" href="/favicon_32x32.png">
    <link rel="apple-touch-icon-precomposed" sizes="16x16" href="/favicon_16x16.png">
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/guide/static/styles.css">
  </head>

  <!--© 2015-2021 Elasticsearch B.V. Copying, publishing and/or distributing without written permission is strictly prohibited.-->

  <body>
    <!-- Google Tag Manager -->
    <script>dataLayer = [];</script><noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-58RLH5" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-58RLH5');</script>
    <!-- End Google Tag Manager -->

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-12395217-16"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', 'UA-12395217-16');
    </script>

    <!--BEGIN QUALTRICS WEBSITE FEEDBACK SNIPPET-->
    <script type="text/javascript">
      (function(){var g=function(e,h,f,g){
      this.get=function(a){for(var a=a+"=",c=document.cookie.split(";"),b=0,e=c.length;b<e;b++){for(var d=c[b];" "==d.charAt(0);)d=d.substring(1,d.length);if(0==d.indexOf(a))return d.substring(a.length,d.length)}return null};
      this.set=function(a,c){var b="",b=new Date;b.setTime(b.getTime()+6048E5);b="; expires="+b.toGMTString();document.cookie=a+"="+c+b+"; path=/; "};
      this.check=function(){var a=this.get(f);if(a)a=a.split(":");else if(100!=e)"v"==h&&(e=Math.random()>=e/100?0:100),a=[h,e,0],this.set(f,a.join(":"));else return!0;var c=a[1];if(100==c)return!0;switch(a[0]){case "v":return!1;case "r":return c=a[2]%Math.floor(100/c),a[2]++,this.set(f,a.join(":")),!c}return!0};
      this.go=function(){if(this.check()){var a=document.createElement("script");a.type="text/javascript";a.src=g;document.body&&document.body.appendChild(a)}};
      this.start=function(){var a=this;window.addEventListener?window.addEventListener("load",function(){a.go()},!1):window.attachEvent&&window.attachEvent("onload",function(){a.go()})}};
      try{(new g(100,"r","QSI_S_ZN_emkP0oSe9Qrn7kF","https://znemkp0ose9qrn7kf-elastic.siteintercept.qualtrics.com/WRSiteInterceptEngine/?Q_ZID=ZN_emkP0oSe9Qrn7kF")).start()}catch(i){}})();
    </script><div id="ZN_emkP0oSe9Qrn7kF"><!--DO NOT REMOVE-CONTENTS PLACED HERE--></div>
    <!--END WEBSITE FEEDBACK SNIPPET-->

    <div id="elastic-nav" style="display:none;"></div>
    <script src="https://www.elastic.co/elastic-nav.js"></script>

    <!-- Subnav -->
    <div>
      <div>
        <div class="tertiary-nav d-none d-md-block">
          <div class="container">
            <div class="p-t-b-15 d-flex justify-content-between nav-container">
              <div class="breadcrum-wrapper"><span><a href="/guide/" style="font-size: 14px; font-weight: 600; color: #000;">Docs</a></span></div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="main-container">
      <section id="content">
        <div class="content-wrapper">

          <section id="guide" lang="en">
            <div class="container">
              <div class="row">
                <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                  <!-- start body -->
                  <div class="page_header">
<strong>IMPORTANT</strong>: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
<a href="../current/index.html">current release documentation</a>.
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="setup.html">Set up Elasticsearch</a></span>
»
<span class="breadcrumb-link"><a href="install-elasticsearch.html">Installing Elasticsearch</a></span>
»
<span class="breadcrumb-node">Install Elasticsearch with Docker</span>
</div>
<div class="navheader">
<span class="prev">
<a href="windows.html">« Install Elasticsearch with Windows MSI Installer</a>
</span>
<span class="next">
<a href="brew.html">Install Elasticsearch on macOS with Homebrew »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="docker"></a>Install Elasticsearch with Docker<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h2>
</div></div></div>
<p>Elasticsearch is also available as Docker images.
The images use <a href="https://hub.docker.com/_/centos/" class="ulink" target="_top">centos:7</a> as the base image.</p>
<p>A list of all published Docker images and tags is available at
<a href="https://www.docker.elastic.co" class="ulink" target="_top">www.docker.elastic.co</a>. The source files
are in
<a href="https://github.com/elastic/elasticsearch/blob/7.7/distribution/docker" class="ulink" target="_top">Github</a>.</p>
<p>These images are free to use under the Elastic license. They contain open source
and free commercial features and access to paid commercial features.
<a href="/guide/en/kibana/7.7/managing-licenses.html" class="ulink" target="_top">Start a 30-day trial</a> to try out all of the
paid commercial features. See the
<a href="/subscriptions" class="ulink" target="_top">Subscriptions</a> page for information about
Elastic license levels.</p>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_pulling_the_image"></a>Pulling the image<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h3>
</div></div></div>
<p>Obtaining Elasticsearch for Docker is as simple as issuing a <code class="literal">docker pull</code> command
against the Elastic Docker registry.</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">docker pull docker.elastic.co/elasticsearch/elasticsearch:7.7.1</pre>
</div>
<p>Alternatively, you can download other Docker images that contain only features
available under the Apache 2.0 license. To download the images, go to
<a href="https://www.docker.elastic.co" class="ulink" target="_top">www.docker.elastic.co</a>.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docker-cli-run-dev-mode"></a>Starting a single node cluster with Docker<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h3>
</div></div></div>
<p>To start a single-node Elasticsearch cluster for development or testing, specify
<a class="xref" href="bootstrap-checks.html#single-node-discovery" title="Single-node discovery">single-node discovery</a> to bypass the <a class="xref" href="bootstrap-checks.html" title="Bootstrap Checks">bootstrap checks</a>:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.7.1</pre>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docker-compose-file"></a>Starting a multi-node cluster with Docker Compose<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h3>
</div></div></div>
<p>To get a three-node Elasticsearch cluster up and running in Docker,
you can use Docker Compose:</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
Create a <code class="literal">docker-compose.yml</code> file:
</li>
</ol>
</div>
<div class="pre_wrapper lang-yaml">
<pre class="programlisting prettyprint lang-yaml">version: '2.2'
services:
  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.7.1
    container_name: es01
    environment:
      - node.name=es01
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es02,es03
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
    networks:
      - elastic
  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.7.1
    container_name: es02
    environment:
      - node.name=es02
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es01,es03
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data02:/usr/share/elasticsearch/data
    networks:
      - elastic
  es03:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.7.1
    container_name: es03
    environment:
      - node.name=es03
      - cluster.name=es-docker-cluster
      - discovery.seed_hosts=es01,es02
      - cluster.initial_master_nodes=es01,es02,es03
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - data03:/usr/share/elasticsearch/data
    networks:
      - elastic

volumes:
  data01:
    driver: local
  data02:
    driver: local
  data03:
    driver: local

networks:
  elastic:
    driver: bridge</pre>
</div>
<p>This sample Docker Compose file brings up a three-node Elasticsearch cluster.
Node <code class="literal">es01</code> listens on <code class="literal">localhost:9200</code> and <code class="literal">es02</code> and <code class="literal">es03</code> talk to <code class="literal">es01</code> over a Docker network.</p>
<p>Please note that this configuration exposes port 9200 on all network interfaces, and given how
Docker manipulates <code class="literal">iptables</code> on Linux, this means that your Elasticsearch cluster is publically accessible,
potentially ignoring any firewall settings. If you don’t want to expose port 9200 and instead use
a reverse proxy, replace <code class="literal">9200:9200</code> with <code class="literal">127.0.0.1:9200:9200</code> in the docker-compose.yml file.
Elasticsearch will then only be accessible from the host machine itself.</p>
<p>The  <a href="https://docs.docker.com/storage/volumes" class="ulink" target="_top">Docker named volumes</a>
<code class="literal">data01</code>, <code class="literal">data02</code>, and <code class="literal">data03</code> store the node data directories so the data persists across restarts.
If they don’t already exist, <code class="literal">docker-compose</code> creates them when you bring up the cluster.</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
<p>Make sure Docker Engine is allotted at least 4GiB of memory.
In Docker Desktop, you configure resource usage on the Advanced tab in Preference (macOS)
or Settings (Windows).</p>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>Docker Compose is not pre-installed with Docker on Linux.
See docs.docker.com for installation instructions:
<a href="https://docs.docker.com/compose/install" class="ulink" target="_top">Install Compose on Linux</a></p>
</div>
</div>
</li>
<li class="listitem">
<p>Run <code class="literal">docker-compose</code> to bring up the cluster:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">docker-compose up</pre>
</div>
</li>
<li class="listitem">
<p>Submit a <code class="literal">_cat/nodes</code> request to see that the nodes are up and running:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">curl -X GET "localhost:9200/_cat/nodes?v&amp;pretty"</pre>
</div>
</li>
</ol>
</div>
<p>Log messages go to the console and are handled by the configured Docker logging driver.
By default you can access logs with <code class="literal">docker logs</code>.</p>
<p>To stop the cluster, run <code class="literal">docker-compose down</code>.
The data in the Docker volumes is preserved and loaded
when you restart the cluster with <code class="literal">docker-compose up</code>.
To <span class="strong strong"><strong>delete the data volumes</strong></span> when you bring down the cluster,
specify the <code class="literal">-v</code> option: <code class="literal">docker-compose down -v</code>.</p>
<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="next-getting-started-tls-docker"></a>Start a multi-node cluster with TLS enabled<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h4>
</div></div></div>
<p>See <a class="xref" href="configuring-tls-docker.html" title="Encrypting communications in an Elasticsearch Docker Container">Encrypting communications in an Elasticsearch Docker Container</a> and
<a href="/guide/en/elastic-stack-get-started/7.7/get-started-docker.html#get-started-docker-tls" class="ulink" target="_top">Run the Elastic Stack in Docker with TLS enabled</a>.</p>
</div>

</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docker-prod-prerequisites"></a>Using the Docker images in production<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h3>
</div></div></div>
<p>The following requirements and recommendations apply when running Elasticsearch in Docker in production.</p>
<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="_set_vm_max_map_count_to_at_least_262144"></a>Set <code class="literal">vm.max_map_count</code> to at least <code class="literal">262144</code><a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h4>
</div></div></div>
<p>The <code class="literal">vm.max_map_count</code> kernel setting must be set to at least <code class="literal">262144</code> for production use.</p>
<p>How you set <code class="literal">vm.max_map_count</code> depends on your platform:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
<p>Linux</p>
<p>The <code class="literal">vm.max_map_count</code> setting should be set permanently in <code class="literal">/etc/sysctl.conf</code>:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">grep vm.max_map_count /etc/sysctl.conf
vm.max_map_count=262144</pre>
</div>
<p>To apply the setting on a live system, run:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">sysctl -w vm.max_map_count=262144</pre>
</div>
</li>
<li class="listitem">
<p>macOS with  <a href="https://docs.docker.com/docker-for-mac" class="ulink" target="_top">Docker for Mac</a></p>
<p>The <code class="literal">vm.max_map_count</code> setting must be set within the xhyve virtual machine:</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
<p>From the command line, run:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty</pre>
</div>
</li>
<li class="listitem">
<p>Press enter and use`sysctl` to configure <code class="literal">vm.max_map_count</code>:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">sysctl -w vm.max_map_count=262144</pre>
</div>
</li>
<li class="listitem">
To exit the <code class="literal">screen</code> session, type <code class="literal">Ctrl a d</code>.
</li>
</ol>
</div>
</li>
<li class="listitem">
<p>Windows and macOS with <a href="https://www.docker.com/products/docker-desktop" class="ulink" target="_top">Docker Desktop</a></p>
<p>The <code class="literal">vm.max_map_count</code> setting must be set via docker-machine:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">docker-machine ssh
sudo sysctl -w vm.max_map_count=262144</pre>
</div>
</li>
</ul>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="_configuration_files_must_be_readable_by_the_elasticsearch_user"></a>Configuration files must be readable by the <code class="literal">elasticsearch</code> user<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h4>
</div></div></div>
<p>By default, Elasticsearch runs inside the container as user <code class="literal">elasticsearch</code> using
uid:gid <code class="literal">1000:0</code>.</p>
<div class="important admon">
<div class="icon"></div>
<div class="admon_content">
<p>One exception is <a href="https://docs.openshift.com/container-platform/3.6/creating_images/guidelines.html#openshift-specific-guidelines" class="ulink" target="_top">Openshift</a>,
which runs containers using an arbitrarily assigned user ID.
Openshift presents persistent volumes with the gid set to <code class="literal">0</code>, which works without any adjustments.</p>
</div>
</div>
<p>If you are bind-mounting a local directory or file, it must be readable by the <code class="literal">elasticsearch</code> user.
In addition, this user must have write access to the <a class="xref" href="path-settings.html" title="path.data and path.logs">data and log dirs</a>.
A good strategy is to grant group access to gid <code class="literal">0</code> for the local directory.</p>
<p>For example, to prepare a local directory for storing data through a bind-mount:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">mkdir esdatadir
chmod g+rwx esdatadir
chgrp 0 esdatadir</pre>
</div>
<p>As a last resort, you can force the container to mutate the ownership of
any bind-mounts used for the <a class="xref" href="path-settings.html" title="path.data and path.logs">data and log dirs</a> through the
environment variable <code class="literal">TAKE_FILE_OWNERSHIP</code>. When you do this, they will be owned by
uid:gid <code class="literal">1000:0</code>, which provides the required read/write access to the Elasticsearch process.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="_increase_ulimits_for_nofile_and_nproc"></a>Increase ulimits for nofile and nproc<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h4>
</div></div></div>
<p>Increased ulimits for <a class="xref" href="setting-system-settings.html" title="Configuring system settings">nofile</a> and <a class="xref" href="max-number-threads-check.html" title="Maximum number of threads check">nproc</a>
must be available for the Elasticsearch containers.
Verify the <a href="https://github.com/moby/moby/tree/ea4d1243953e6b652082305a9c3cda8656edab26/contrib/init" class="ulink" target="_top">init system</a>
for the Docker daemon sets them to acceptable values.</p>
<p>To check the Docker daemon defaults for ulimits, run:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">docker run --rm centos:7 /bin/bash -c 'ulimit -Hn &amp;&amp; ulimit -Sn &amp;&amp; ulimit -Hu &amp;&amp; ulimit -Su'</pre>
</div>
<p>If needed, adjust them in the Daemon or override them per container.
For example, when using <code class="literal">docker run</code>, set:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">--ulimit nofile=65535:65535</pre>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="_disable_swapping"></a>Disable swapping<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h4>
</div></div></div>
<p>Swapping needs to be disabled for performance and node stability.
For information about ways to do this, see <a class="xref" href="setup-configuration-memory.html" title="Disable swapping">Disable swapping</a>.</p>
<p>If you opt for the <code class="literal">bootstrap.memory_lock: true</code> approach,
you also need to define the <code class="literal">memlock: true</code> ulimit in the
<a href="https://docs.docker.com/engine/reference/commandline/dockerd/#default-ulimits" class="ulink" target="_top">Docker Daemon</a>,
or explicitly set for the container as shown in the  <a class="xref" href="docker.html#docker-compose-file" title="Starting a multi-node cluster with Docker Compose">sample compose file</a>.
When using <code class="literal">docker run</code>, you can specify:</p>
<pre class="literallayout">-e "bootstrap.memory_lock=true" --ulimit memlock=-1:-1</pre>

</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="_randomize_published_ports"></a>Randomize published ports<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h4>
</div></div></div>
<p>The image <a href="https://docs.docker.com/engine/reference/builder/#/expose" class="ulink" target="_top">exposes</a>
TCP ports 9200 and 9300. For production clusters, randomizing the
published ports with <code class="literal">--publish-all</code> is recommended,
unless you are pinning one container per host.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="docker-set-heap-size"></a>Set the heap size<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h4>
</div></div></div>
<p>To configure the heap size, you can bind mount a <a class="xref" href="jvm-options.html" title="Setting JVM options">JVM options</a>
file under <code class="literal">/usr/share/elasticsearch/config/jvm.options.d</code> that includes your
desired <a class="xref" href="heap-size.html" title="Setting the heap size">heap size</a> settings. Note that while the default root
<code class="literal">jvm.options</code> file sets a default heap of 1 GB, any value you set in a
bind-mounted JVM options file will override it.</p>
<p>While setting the heap size via bind-mounted JVM options is the recommended
method, you can also configure this by using the <code class="literal">ES_JAVA_OPTS</code> environment
variable to set the heap size. For example, to use 16 GB, specify
<code class="literal">-e ES_JAVA_OPTS="-Xms16g -Xmx16g"</code> with <code class="literal">docker run</code>. Note that while the
default root <code class="literal">jvm.options</code> file sets a default heap of 1 GB, any value you set
in <code class="literal">ES_JAVA_OPTS</code> will override it. The <code class="literal">docker-compose.yml</code> file above sets the heap size to 512 MB.</p>
<div class="important admon">
<div class="icon"></div>
<div class="admon_content">
<p>You must <a class="xref" href="heap-size.html" title="Setting the heap size">configure the heap size</a> even if you are
<a href="https://docs.docker.com/config/containers/resource_constraints/#limit-a-containers-access-to-memory" class="ulink" target="_top">limiting
memory access</a> to the container.</p>
</div>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="_pin_deployments_to_a_specific_image_version"></a>Pin deployments to a specific image version<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h4>
</div></div></div>
<p>Pin your deployments to a specific version of the Elasticsearch Docker image. For
example <code class="literal">docker.elastic.co/elasticsearch/elasticsearch:7.7.1</code>.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="_always_bind_data_volumes"></a>Always bind data volumes<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h4>
</div></div></div>
<p>You should use a volume bound on <code class="literal">/usr/share/elasticsearch/data</code> for the following reasons:</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
The data of your Elasticsearch node won’t be lost if the container is killed
</li>
<li class="listitem">
Elasticsearch is I/O sensitive and the Docker storage driver is not ideal for fast I/O
</li>
<li class="listitem">
It allows the use of advanced
<a href="https://docs.docker.com/engine/extend/plugins/#volume-plugins" class="ulink" target="_top">Docker volume plugins</a>
</li>
</ol>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="_avoid_using_loop_lvm_mode"></a>Avoid using <code class="literal">loop-lvm</code> mode<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h4>
</div></div></div>
<p>If you are using the devicemapper storage driver, do not use the default <code class="literal">loop-lvm</code> mode.
Configure docker-engine to use
<a href="https://docs.docker.com/engine/userguide/storagedriver/device-mapper-driver/#configure-docker-with-devicemapper" class="ulink" target="_top">direct-lvm</a>.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="_centralize_your_logs"></a>Centralize your logs<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h4>
</div></div></div>
<p>Consider centralizing your logs by using a different
<a href="https://docs.docker.com/engine/admin/logging/overview/" class="ulink" target="_top">logging driver</a>. Also
note that the default json-file logging driver is not ideally suited for
production use.</p>
</div>

</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docker-configuration-methods"></a>Configuring Elasticsearch with Docker<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h3>
</div></div></div>
<p>When you run in Docker, the <a class="xref" href="settings.html#config-files-location" title="Config files location">Elasticsearch configuration files</a> are loaded from
<code class="literal">/usr/share/elasticsearch/config/</code>.</p>
<p>To use custom configuration files, you <a class="xref" href="docker.html#docker-config-bind-mount" title="Mounting Elasticsearch configuration files">bind-mount the files</a>
over the configuration files in the image.</p>
<p>You can set individual Elasticsearch configuration parameters using Docker environment variables.
The <a class="xref" href="docker.html#docker-compose-file" title="Starting a multi-node cluster with Docker Compose">sample compose file</a> and the
<a class="xref" href="docker.html#docker-cli-run-dev-mode" title="Starting a single node cluster with Docker">single-node example</a> use this method.</p>
<p>To use the contents of a file to set an environment variable, suffix the environment
variable name with <code class="literal">_FILE</code>. This is useful for passing secrets such as passwords to Elasticsearch
without specifying them directly.</p>
<p>For example, to set the Elasticsearch bootstrap password from a file, you can bind mount the
file and set the <code class="literal">ELASTIC_PASSWORD_FILE</code> environment variable to the mount location.
If you mount the password file to <code class="literal">/run/secrets/password.txt</code>, specify:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">-e ELASTIC_PASSWORD_FILE=/run/secrets/bootstrapPassword.txt</pre>
</div>
<p>You can also override the default command for the image to pass Elasticsearch configuration
parameters as command line options. For example:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">docker run &lt;various parameters&gt; bin/elasticsearch -Ecluster.name=mynewclustername</pre>
</div>
<p>While bind-mounting your configuration files is usually the preferred method in production,
you can also <a class="xref" href="docker.html#_c_customized_image" title="Using custom Docker images">create a custom Docker image</a>
that contains your configuration.</p>
<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="docker-config-bind-mount"></a>Mounting Elasticsearch configuration files<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h4>
</div></div></div>
<p>Create custom config files and bind-mount them over the corresponding files in the Docker image.
For example, to bind-mount <code class="literal">custom_elasticsearch.yml</code> with <code class="literal">docker run</code>, specify:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">-v full_path_to/custom_elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml</pre>
</div>
<div class="important admon">
<div class="icon"></div>
<div class="admon_content">
<p>The container <span class="strong strong"><strong>runs Elasticsearch as user <code class="literal">elasticsearch</code> using
uid:gid <code class="literal">1000:0</code></strong></span>. Bind mounted host directories and files must be accessible by this user,
and the data and log directories must be writable by this user.</p>
</div>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="docker-keystore-bind-mount"></a>Mounting an Elasticsearch keystore<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h4>
</div></div></div>
<p>By default, Elasticsearch will auto-generate a keystore file for secure settings. This
file is obfuscated but not encrypted. If you want to encrypt your
<a class="xref" href="secure-settings.html" title="Secure settings">secure settings</a> with a password, you must use the
<code class="literal">elasticsearch-keystore</code> utility to create a password-protected keystore and
bind-mount it to the container as
<code class="literal">/usr/share/elasticsearch/config/elasticsearch.keystore</code>. In order to provide
the Docker container with the password at startup, set the Docker environment
value <code class="literal">KEYSTORE_PASSWORD</code> to the value of your password. For example, a <code class="literal">docker
run</code> command might have the following options:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">-v full_path_to/elasticsearch.keystore:/usr/share/elasticsearch/config/elasticsearch.keystore
-E KEYSTORE_PASSWORD=mypassword</pre>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h4 class="title">
<a id="_c_customized_image"></a>Using custom Docker images<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/docker.asciidoc">edit</a>
</h4>
</div></div></div>
<p>In some environments, it might make more sense to prepare a custom image that contains
your configuration. A <code class="literal">Dockerfile</code> to achieve this might be as simple as:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">FROM docker.elastic.co/elasticsearch/elasticsearch:7.7.1
COPY --chown=elasticsearch:elasticsearch elasticsearch.yml /usr/share/elasticsearch/config/</pre>
</div>
<p>You could then build and run the image with:</p>
<div class="pre_wrapper lang-sh">
<pre class="programlisting prettyprint lang-sh">docker build --tag=elasticsearch-custom .
docker run -ti -v /usr/share/elasticsearch/data elasticsearch-custom</pre>
</div>
<p>Some plugins require additional security permissions.
You must explicitly accept them either by:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
Attaching a <code class="literal">tty</code> when you run the Docker image and allowing the permissions when prompted.
</li>
<li class="listitem">
Inspecting the security permissions and accepting them (if appropriate) by adding the <code class="literal">--batch</code> flag to the plugin install command.
</li>
</ul>
</div>
<p>See <a href="/guide/en/elasticsearch/plugins/7.7/_other_command_line_parameters.html" class="ulink" target="_top">Plugin management</a>
for more information.</p>
</div>

</div>

<div class="section exclude">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_next_steps_6"></a>Next steps<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/setup/install/next-steps.asciidoc">edit</a>
</h3>
</div></div></div>
<p>You now have a test Elasticsearch environment set up.  Before you start
serious development or go into production with Elasticsearch, you must do some additional
setup:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
Learn how to <a class="xref" href="settings.html" title="Configuring Elasticsearch">configure Elasticsearch</a>.
</li>
<li class="listitem">
Configure <a class="xref" href="important-settings.html" title="Important Elasticsearch configuration">important Elasticsearch settings</a>.
</li>
<li class="listitem">
Configure <a class="xref" href="system-config.html" title="Important System Configuration">important system settings</a>.
</li>
</ul>
</div>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="windows.html">« Install Elasticsearch with Windows MSI Installer</a>
</span>
<span class="next">
<a href="brew.html">Install Elasticsearch on macOS with Homebrew »</a>
</span>
</div>
</div>

                  <!-- end body -->
                </div>
                <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                  <div id="rtpcontainer" style="display: block;">
                    <div class="mktg-promo">
                      <h3>Most Popular</h3>
                      <ul class="icons">
                        <li class="icon-elasticsearch-white"><a href="https://www.elastic.co/webinars/getting-started-elasticsearch?baymax=default&amp;elektra=docs&amp;storm=top-video">Get Started with Elasticsearch: Video</a></li>
                        <li class="icon-kibana-white"><a href="https://www.elastic.co/webinars/getting-started-kibana?baymax=default&amp;elektra=docs&amp;storm=top-video">Intro to Kibana: Video</a></li>
                        <li class="icon-logstash-white"><a href="https://www.elastic.co/webinars/introduction-elk-stack?baymax=default&amp;elektra=docs&amp;storm=top-video">ELK for Logs &amp; Metrics: Video</a></li>
                      </ul>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </section>

        </div>


<div id="elastic-footer"></div>
<script src="https://www.elastic.co/elastic-footer.js"></script>
<!-- Footer Section end-->

      </section>
    </div>

<script src="/guide/static/jquery.js"></script>
<script type="text/javascript" src="/guide/static/docs.js"></script>
<script type="text/javascript">
  window.initial_state = {}</script>
  </body>
</html>
